package cn.kawa.pet.service.impl;

import cn.kawa.pet.domain.Pet;
import cn.kawa.pet.domain.PetDetail;
import cn.kawa.pet.mapper.PetDetailMapper;
import cn.kawa.pet.mapper.PetMapper;
import cn.kawa.pet.service.IPetService;
import cn.kawa.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 业务实现类：
 */
@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {
    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;


    @Override
    public void add(Pet pet) {
        // 先添加pet，返回自增的主键
        petMapper.save(pet);

        // 再添加pet_datail
        PetDetail petDetail = pet.getPetDetail();
        petDetail.setPetId(pet.getId());
        petDetailMapper.save(petDetail);

    }

    @Override
    public void update(Pet pet) {
        // pet
        petMapper.update(pet);
        // detail
        petDetailMapper.update(pet.getPetDetail());
    }

    /**
     *
     * @param ids
     */
    @Override
    public void onSale(List<Long> ids) {
        //1.审核通过上架，没通过自定异常，，每次审核都要保存log



        /**
         * 改状态：state=1
         * 改上架时间:new Date()
         *
         */
        petMapper.onSale(ids,new Date());

    }

    @Override
    public void offSale(List<Long> ids) {
        /**
         * 改状态：state=0
         * 改下架时间:new Date()
         *
         */
        petMapper.offSale(ids,new Date());
    }
}
